<template>
  <div class="login" clearfix>
    <div align="center" class="login-title">猪猪侠ERP管理系统</div>
    <div class="login-wrap">
      <el-row type="flex" justify="center">
        <el-form ref="loginForm" :model="user" status-icon label-width="80px">
          <h3>登录</h3>
          <hr>
          <el-form-item prop="username" label="用户名">
            <el-input v-model="user.account" placeholder="请输入用户名" prefix-icon></el-input>
          </el-form-item>
          <el-form-item id="password" prop="password" label="密码">
            <el-input v-model="user.password" show-password placeholder="请输入密码"></el-input>
          </el-form-item>
          <div style="height: 15px"></div>
          <el-form-item align="center">
            <el-button type="primary" icon="el-icon-upload" @click="doLogin()">登 录</el-button>
          </el-form-item>
        </el-form>
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      user: {
        account: "",
        password: ""
      }
    };
  },
  created() {},
  methods: {
    doLogin() {
      if (!this.user.account) {
        this.$message.error("请输入用户名！");
        return;
      } else if (!this.user.password) {
        this.$message.error("请输入密码！");
        return;
      } else {
        //校验用户名和密码是否正确;
        // this.$router.push({ path: "/personal" });
        this.axios({
          method:"post",
          url:this.baseUrl+"auth/login/",
          data:this.user
        }).then(res=>{
          //console.log(res.data);
          if(res.data.status === 'LOGIN_SUCCESS'){
            this.$store.commit("setGrades",this.user);
            console.log(this.$store.state.grades);
            this.$router.push("/menu");
            
          }
          if(res.data.status === 'LOGIN_FAIL'){
            this.$message.error("用户名或密码错误！");
            
          }
          if(res.data.status === 'LOGIN_AGAIN'){
            this.$message.error("请勿重复登录！");
            
          }
          
        })

      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.login {
  width: 100%;
  height: 900px;
  background: url("../assets/images/bg1.png") no-repeat;
  background-size: cover;
  overflow: hidden;
}
.login-title {
  font-size: 28px;
  color: #fff;
  text-align: center;
  margin-top: 200px;
}
.login-wrap {
  background: url("../assets/images/login_bg.png") no-repeat;
  background-size: cover;
  width: 400px;
  height: 300px;
  margin-top: 10px;
  margin-left: 39%;
  overflow: hidden;
  padding-top: 10px;
  line-height: 40px;
  opacity: 0.8;
  border-radius: 20px;

}

#password {
  margin-bottom: 5px;
}
h3 {
  color: #0babeab8;
  font-size: 24px;
}
hr {
  background-color: #444;
  margin: 20px auto;
}
a {
  text-decoration: none;
  color: #aaa;
  font-size: 15px;
}
a:hover {
  color: coral;
}
.el-button {
  width: 80%;
  margin-left: -50px;
}
</style>
